﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ImageProcess;
using mshtml;
using System.Diagnostics;
using ColorPicker;
using yt.DataModel;

namespace yt
{
    public partial class frmMain : Form
    {
        public delegate bool EnumChildWindowsProc(IntPtr hwnd, IntPtr lParam);
        public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
        public IntPtr sendkeys { get; set; }
        public int serialno { get; set; }

        public frmMain()
        {
            InitializeComponent();
            lstLocation = new List<ScreenPoint>();
            Process currentProcess = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
            serialno = processes.Count(process => process.Id != currentProcess.Id);
            txtNo.Text = serialno.ToString(CultureInfo.InvariantCulture);
            if (!System.IO.File.Exists(DataOp.DBName))
            {
                DataOp.initUser();
                DataOp.initData();
            }
            List<Users> users = DataOp.ReadUsers().ToList();
            comboBox1.DataSource = users;
            comboBox1.DisplayMember = "Description";
            comboBox1.SelectedIndex = serialno;
            filldata();
            grdData.AutoGenerateColumns = false;
            grdData.DataSource = DataOp.GetQuizList();
            
            colAsk.DataPropertyName = "Quiz";
            colAsn.DataPropertyName = "Result";
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }
        /// <summary>
        /// 钓鱼
        /// </summary>
        private void DY()
        {
            int deloy = 3000;
            if (serialno == 0)
            {
                deloy = 7000;//第一个号延迟7秒
            }
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(50, 300)),
                new ScreenPoint(new Point(745, 440)),
                new ScreenPoint(new Point(1408, 65)),
                new ScreenPoint(new Point(832, 320)),
                new ScreenPoint(new Point(745, 441), deloy),
                new ScreenPoint(new Point(670, 584))
            };
            //lstLocation.Add(new Point(642, 228));
            //过图
            //lstLocation.Add(new Point(629, 540));
            Doaction();

        }
        /// <summary>
        /// Boss
        /// </summary>
        private void BS()
        {
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(1408, 65)),
                new ScreenPoint(new Point(834, 544), 3000),
                new ScreenPoint(new Point(1440, 160)),
                new ScreenPoint(WinAPI.VK_ESCAPE)
            };
            //lstLocation.Add(new Point(1185, 275));
            //lstLocation.Add(new Point(745, 440));
            //lstLocation.Add(new Point(642, 228));
            Doaction();
        }

        /// <summary>
        /// Boss
        /// </summary>
        private void BH()
        {
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(1408, 65)),
                new ScreenPoint(new Point(830, 385)),
                new ScreenPoint(new Point(745, 440),3000),
                new ScreenPoint(WinAPI.VK_ESCAPE)
            };
            //lstLocation.Add(new Point(1185, 275));
            //lstLocation.Add(new Point(745, 440));
            //lstLocation.Add(new Point(642, 228));
            Doaction();
        }
        /// <summary>
        /// 昆仑
        /// </summary>
        private void KL()
        {
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(745, 280), 3000),
                new ScreenPoint(WinAPI.VK_ESCAPE)
                //new ScreenPoint(new Point(1007, 210))
            };
            Doaction();
        }

        /// <summary>
        /// 武林大会
        /// </summary>
        private void WL()
        {
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(745, 435), 3000),
                new ScreenPoint(WinAPI.VK_ESCAPE)
                //new ScreenPoint(new Point(960, 170))
            };
            Doaction();
        }

        private void SY()
        {
            lstLocation = new List<ScreenPoint>
            {
                new ScreenPoint(new Point(975, 540)),
                new ScreenPoint(new Point(800, 505)),
                new ScreenPoint(new Point(800, 505)),
                new ScreenPoint(new Point(800, 505)),
                new ScreenPoint(WinAPI.VK_ESCAPE)
                //new ScreenPoint(new Point(970, 170))
            };
            Doaction();
        }

        private void Doaction()
        {
            WinAPI.EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
            //int screenx = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            //int screeny = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

            foreach (var lco in this.lstLocation)
            {
                //this.locationxy = lco;
                //mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, lco.X, lco.Y, 0, 0);//移动到需要点击的位置
                if (lco.KeyType == KeyType.V_KEY)
                {
                    WinAPI.SendKey(this.FlashHandle, lco.keyInput);
                }
                else
                {
                    WinAPI.SendClick(this.Handle, this.FlashHandle, lco.ScPoint);
                }

                //System.Threading.Thread.Sleep(2000); //(2000);
                WinAPI.Delay(lco.DeloyTime);

            }
        }

        private void Doaction(List<ScreenPoint> screenPoints)
        {
            WinAPI.EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
            //int screenx = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            //int screeny = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

            foreach (var lco in screenPoints)
            {
                //this.locationxy = lco;
                //mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, lco.X, lco.Y, 0, 0);//移动到需要点击的位置
                if (lco.KeyType == KeyType.V_KEY)
                {
                    WinAPI.SendKey(this.FlashHandle, lco.keyInput);
                }
                else
                {
                    WinAPI.SendClick(this.Handle, this.FlashHandle, lco.ScPoint);
                }

                //System.Threading.Thread.Sleep(2000); //(2000);
                WinAPI.Delay(lco.DeloyTime);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //this.sendkeys = (IntPtr)'B';
            //EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
            //List<Point> lstLoc=new List<Point>();

            ////lstLoc.Add(new Point(745, 441));
            ////lstLoc.Add(new Point(624, 546));
            ////lstLoc.Add(new Point(660, 530));
            ////lstLoc.Add(new Point(832, 355));
            //int screenx = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            //int screeny = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

            //foreach (var lco in lstLoc)
            //{
            //    this.locationxy = lco;
            //    //mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, lco.X, lco.Y, 0, 0);//移动到需要点击的位置
            //    SendClick(this.FlashHandle, this.locationxy);
            //    Delay(2000);

            //}
            //MessageBox.Show("aa");
            //Delay(10000);
            //this.locationxy = new Point(624, 566);
            //mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, locationxy.X * 65535 / screenx, locationxy.Y * 65535 / screeny, 0, 0);//移动到需要点击的位置
            //mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, locationxy.X * 65535 / screenx, locationxy.Y * 65535 / screeny, 0, 0);//点击
            //mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, locationxy.X * 65535 / screenx, locationxy.Y * 65535 / screeny, 0, 0);//抬起
            //SendClick(this.FlashHandle, this.locationxy);
            //DY();
            //BS();
            webBrowser1.Navigate("http://yi.qq.com/server/website/startgame.shtml");
            webBrowser1.Document.MouseDown += Document_MouseDown;
        }

        void Document_MouseDown(object sender, HtmlElementEventArgs e)
        {
            //e.MousePosition.X;
        }

        private bool EnumChildWindowsCallback(IntPtr handle, IntPtr lparam)
        {
            StringBuilder className = new StringBuilder(100);
            WinAPI.GetClassName(handle, className, className.Capacity);
            //MessageBox.Show(className.ToString());

            string cn = className.ToString();
            if (className.ToString() == "MacromediaFlashPlayerActiveX")
            {
                // Point point = GetFlashPointFromHandle(handle);
                // if (point.X == ((webBrowser1.Document.DomDocument) as HTMLDocument).getElementById("obj1").offsetLeft && point.Y == ((webBrowser1.Document.DomDocument) as HTMLDocument).getElementById("obj1").offsetTop)
                // {
                //webBrowser1.Document.Body.ScrollTop = 100;
                //int x = Convert.ToInt32("1032"); // X coordinate of the click
                //int y = Convert.ToInt32("140"); // Y coordinate of the click
                //IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
                //IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
                //const uint downCode = 0x201; // Left click down code
                //const uint upCode = 0x202; // Left click up code
                //SendMessage(handle, downCode, wParam, lParam); // Mouse button down
                //SendMessage(handle, upCode, wParam, lParam); // Mouse button up
                //SendEnter(handle);
                //SendChar(handle, Convert.ToInt16('B'));
                //SendMessage(handle, WM_KEYDOWN, this.sendkeys, lParam);
                //SendMessage(handle, WM_KEYUP, this.sendkeys, lParam);
                //Point p = new Point(1032, 140);
                this.FlashHandle = handle;
                //SendClick(handle, this.locationxy);
                //SendMessage(handle, WM_KEYDOWN, (IntPtr)VK_ENTER, IntPtr.Zero);
                //SendMessage(handle, WM_KEYUP, (IntPtr)VK_ENTER, IntPtr.Zero);
                //SendMessage(handle, WM_KEYDOWN, (IntPtr)13, lParam);
                //SendMessage(handle, WM_KEYUP, (IntPtr)13, lParam);
                //}
            }
            return true;
        }


        private void button2_Click(object sender, EventArgs e)
        {

            //WinAPI.EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
            //sendmin = 11;
            //SetStartTime();
            //serialno = Convert.ToInt16(txtNo.Text);
            this.StartProcess = true;
            timer1.Enabled = true;
            //int x = 140;
            //int y = 1032;
            //Point p = new Point(1032, 140);
            //SendClick(IntPtr.Zero, p);
            //Point p1 = PointToClient(p);//PointToScreen();
            //x = p1.X;
            //y = p1.Y;
            ////屏幕的分辨率
            //int screenx = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            //int screeny = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            ////绝对位置
            //mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x * 65535 / screenx, y * 65535 / screeny, 0, 0);//移动到需要点击的位置
            //mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, x * 65535 / screenx, y * 65535 / screeny, 0, 0);//点击
            //mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, x * 65535 / screenx, y * 65535 / screeny, 0, 0);//抬起
            //相对位置  指的是相对于当前鼠标的相对位置
            //mouse_event(MOUSEEVENTF_MOVE, x, y, 0, 0);//移动
            //mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);//点击
            //mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);//抬起
            //this.sendkeys = (IntPtr)VK_ENTER;
            //EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
        }
        public int sendmin { get; set; }


        private void sendkey(IntPtr key)
        {
            this.sendkeys = key;
            WinAPI.EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用
        }
        //private int inta = 0;
        public Point locationxy { get; set; }

        public IntPtr FlashHandle { get; set; }

        public List<ScreenPoint> lstLocation { get; set; }
        //private bool entered = true;
        private DateTime stime = new DateTime();

        private void timer1_Tick(object sender, EventArgs e)
        {
            //昆仑
            label4.Text = "正在挂机。。。";
            if (Runners == null) return;
            var oTask =
                Runners.Where(
                    runner1 =>
                        runner1.StartTime.Hour == DateTime.Now.Hour && DateTime.Now >= runner1.StartTime && DateTime.Now <= runner1.EndTime &&
                        runner1.RunStatus == RunStatus.VReady && runner1.Started == false
                        && runner1.WeekDay.Contains(((int)DateTime.Now.DayOfWeek).ToString(CultureInfo.InvariantCulture))
                        ).ToList();
            foreach (var runner in oTask)
            {
                runner.RunStatus = RunStatus.VRuning;
                runner.Started = true;
                timer1.Enabled = false;
                label4.Text = "暂停挂机。。。";
                Doaction(runner.ScreenPoints);
                timer3.Enabled = runner.IsNeedLoop;

            }
            ////this.sendkeys = (IntPtr)'B';
            //if ((DateTime.Now.Hour == 19 && DateTime.Now >= stime && entered))
            //{
            //    timer1.Enabled = false;
            //    label4.Text = "暂停挂机。。。";
            //    KL();
            //    entered = false;
            //    timer3.Enabled = true;

            //}
            ////钓鱼
            ////if (DateTime.Now.Hour == 13 && DateTime.Now.Minute >= stime.Minute && DateTime.Now.Second >= stime.Second && entered)
            //if (DateTime.Now.Hour == 13 && DateTime.Now >= stime && entered)
            //{
            //    timer1.Enabled = false;
            //    label4.Text = "暂停挂机。。。";
            //    DY();
            //    entered = false;
            //    timer3.Interval = 1000;
            //    timer3.Enabled = true;
            //    starttime = DateTime.Now;

            //}
            ////BOSS
            //if (DateTime.Now.Hour == 14 && DateTime.Now >= stime && entered)
            //{
            //    timer1.Enabled = false;
            //    label4.Text = "暂停挂机。。。";
            //    BS();
            //    entered = false;
            //    timer3.Enabled = false;

            //}
            ////武林大会
            //if (DateTime.Now.Hour == 20 && DateTime.Now >= stime && entered)
            //{

            //    if (DateTime.Now.DayOfWeek == System.DayOfWeek.Tuesday ||
            //        DateTime.Now.DayOfWeek == System.DayOfWeek.Thursday ||
            //        DateTime.Now.DayOfWeek == System.DayOfWeek.Saturday)
            //    {
            //        //DateTime.Now.
            //        timer1.Enabled = false;
            //        label4.Text = "暂停挂机。。。";
            //        WL();
            //        entered = false;
            //        timer3.Enabled = false;
            //    }
            //    else if (DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
            //    {
            //        //DateTime.Now.
            //        timer1.Enabled = false;
            //        label4.Text = "暂停挂机。。。";
            //        BH();
            //        entered = false;
            //        timer3.Enabled = false;
            //    }


            //}

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 'X')
            {
                timer1.Enabled = false;
            }
        }
        private void SetStartTime()
        {
            if (DateTime.Now.Hour < 14)//钓鱼
            {
                stime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 00, 30);
                stime = stime.AddSeconds(serialno * 14 + serialno * 10);
            }
            else if (DateTime.Now.Hour == 14)//BOSS
            {
                stime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 26, 10);
                stime = stime.AddSeconds(serialno * 8 + serialno * 5);
            }
            else if (DateTime.Now.Hour > 14 && DateTime.Now.Hour < 20)//昆仑
            {
                stime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 10, 10);
                stime = stime.AddSeconds(serialno * 4 + serialno * 10);
            }
            else if (DateTime.Now.Hour == 20)//武林
            {
                stime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 10, 10);
                stime = stime.AddSeconds(serialno * 4 + serialno * 5);
            }
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (webBrowser1.Document != null) this.Text = comboBox1.Text + "--" + webBrowser1.Document.Title;

            if (chkColor.Checked)
            {
                label1.Text = Cursor.Position.X.ToString(CultureInfo.InvariantCulture);
                label2.Text = Cursor.Position.Y.ToString(CultureInfo.InvariantCulture);
                picColor.BackColor = ColorPickerManager.GetColor(Cursor.Position.X, Cursor.Position.Y);
                label9.Text = @"R:" + picColor.BackColor.R;
                label8.Text = @"G:" + picColor.BackColor.G;
                label7.Text = @"B:" + picColor.BackColor.B;




                if (webBrowser1.Bounds.Contains(this.PointToClient(Cursor.Position)))
                {

                    this.label3.Text = webBrowser1.PointToClient(Cursor.Position).ToString();
                }
            }


            if (timer1.Enabled) return;
            int i = Runners.Count(p => p.EndTime < DateTime.Now && p.Started);
            foreach (var runner in Runners.Where(runner => runner.EndTime < DateTime.Now && runner.Started))
            {

                runner.RunStatus = RunStatus.VFinish;
                runner.Started = false;
                if (i == 1)
                {
                    timer1.Enabled = true;
                    timer3.Enabled = false;

                }
            }

            
        }

        public bool StartProcess { get; set; }

        private void btnStop_Click(object sender, EventArgs e)
        {

            timer1.Enabled = false;
            label4.Text = "停止挂机。。。";
            serialno = 1;

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {

            var runner = from runner1 in Runners
                         where runner1.RunStatus == RunStatus.VRuning
                         select runner1;
            foreach (var runner1 in runner.Where(runner1 => runner1.IsNeedLoop))
            {
                if (runner1.IsResetScreen)
                {
                    if (runner1.ResetDeloy == runner1.LoopCount && !runner1.IsReseted)
                    {
                        runner1.IsReseted = true;
                        WinAPI.ShowWindows(this.Handle, 0);
                        WinAPI.Delay(2000);
                        WinAPI.ShowWindows(this.Handle, 1);
                    }

                }
                if (runner1.LoopCount == runner1.LoopDeloy)
                {
                    runner1.LoopCount = 0;
                    if (runner1.LoopType == LoopType.VPotint)
                    {
                        Doaction(runner1.LoopEvent);
                    }
                    else
                    {
                        long tick = DateTime.Now.Ticks;
                        Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
                        WinAPI.SendClick(this.Handle, this.FlashHandle,
                            new Point(ran.Next(280, 1310), ran.Next(230, 660)));
                    }
                }
                else
                {
                    runner1.LoopCount++;
                }
            }

        }

        private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void webBrowser1_FileDownload(object sender, EventArgs e)
        {

        }

        private void webBrowser1_ControlAdded(object sender, ControlEventArgs e)
        {
            label6.Text = e.Control.Name;

        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            WinAPI.EnumChildWindows(webBrowser1.Handle, new EnumChildWindowsProc(EnumChildWindowsCallback), IntPtr.Zero);//调用

            //ScreenCaptureLib.Screenshot.
            //Utilities.CaptureWindow(this.FlashHandle).Save("shot.bmp", ImageFormat.Bmp);
            string filename = @"20140329155959.jpg";
            if (System.IO.File.Exists(filename))
            {
                Bitmap templateBitmap = new Bitmap(filename);
                Point resultl = new Point();
                bool IsFound;
                Utilities.ImageMatch(templateBitmap, (Bitmap)Utilities.CaptureWindow(this.FlashHandle), out resultl,out IsFound);
                if (IsFound)
                {
                    WinAPI.SendClick(this.Handle, this.FlashHandle, resultl);
                }
                
            }
            
            //webBrowser1.Refresh();
        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            //DataOp.initData();
            Users user = comboBox1.SelectedItem as Users;
            var doc = this.webBrowser1.Document;
            if (doc != null)
            {
                var frames = doc.Window.Frames;
                if (frames == null)
                {
                    return;
                }
                for (int i = 0; i < frames.Count; i++)
                {
                    IHTMLDocument3 baiduDoc = CorssDomainHelper.GetDocumentFromWindow(frames[i].DomWindow as IHTMLWindow2);
                    try
                    {
                        var a = baiduDoc.getElementById("u");
                        if (a == null) continue;

                        string uid = user.Username, pwd = user.Password;

                        baiduDoc.getElementById("u").setAttribute("value", uid);
                        baiduDoc.getElementById("p").setAttribute("value", pwd);
                        //baiduDoc.getElementById("login_button").click();
                        break;
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
        }

        public List<Runner> Runners { get; set; }

        private void filldata()
        {
            int deloy = 3000;//第一个号延迟

            Runners = DataOp.GetTaskList();
            foreach (var setTime in Runners)
            {
                setTime.StartTime = setTime.StartTime.AddSeconds(serialno * setTime.ScreenPoints.Count + serialno * 5);
                if (serialno != 0) continue;
                foreach (var scPoint in setTime.ScreenPoints.Where(p => p.DeloyTime > 1000))
                {
                    scPoint.DeloyTime = scPoint.DeloyTime + deloy;
                }
            }
            if (Runners.Count == 0)
            {
                MessageBox.Show("没有设定任务");
            }

        }

        private void chkQuiz_CheckedChanged(object sender, EventArgs e)
        {
            if (chkQuiz.Checked)
            {
                panel1.Width = Convert.ToInt32(Width*0.3);
                webBrowser1.Width = this.Width - panel1.Width - 1;
                panel1.Visible = true;
            }
            else
            {
                panel1.Visible = false;
                webBrowser1.Width = this.Width;
            }
        }

        private string GetRadioValueOfGroupBox(Control.ControlCollection controls)
        {
            string message = string.Empty;
            foreach (RadioButton radio in controls.Cast<RadioButton>().Where(radio => radio != null && radio.Checked))
            {
                message = radio.Text;
            }
            return message;
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void filterdata()
        {
            int part = Convert.ToInt32(GetRadioValueOfGroupBox(groupBox1.Controls));
            //var ds = DataOp.GetQuizList().Where(p => p.Part == part && p.Quiz.IndexOf(txtSearch.Text, System.StringComparison.Ordinal) > 0);

            var quizs = string.IsNullOrEmpty(txtSearch.Text)
                ? (from quiz in DataOp.GetQuizList()
                   where quiz.Part == part
                   select quiz).ToList()
                : (from quiz in DataOp.GetQuizList()
                   where quiz.Part == part && quiz.Quiz.Contains(txtSearch.Text)
                   select quiz).ToList();


            grdData.DataSource = quizs;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            filterdata();
        }

        private void btnClean_Click(object sender, EventArgs e)
        {
            txtSearch.Text = "";
        }

        private void chkColor_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
